package com.ubing.boot.notesforjava.test.json;

import io.lettuce.core.ScriptOutputType;

import java.time.*;

public class tt {
//    public static boolean isTimeInToday(LocalDateTime dateTime) {
//        LocalDate today = LocalDate.now();
//        LocalDate date = dateTime.toLocalDate();
//
//        return today.equals(date);
//    }
//
//    public static void main(String[] args) {
//        // 获取当前日期时间
//        LocalDateTime now = LocalDateTime.now();
//
//        // 在今天的时间
//        LocalDateTime inToday = LocalDateTime.of(LocalDate.now(), LocalTime.of(12, 0));
//
//        // 不在今天的时间
//        LocalDateTime notInToday = LocalDateTime.of(LocalDate.now().minusDays(1), LocalTime.of(12, 0));
//
//        System.out.println(isTimeInToday(now)); // 输出：true
//        System.out.println(isTimeInToday(inToday)); // 输出：true
//        System.out.println(isTimeInToday(notInToday)); // 输出：false
//    }

    public static void main(String[] args) {
        // 获取当前日期
        LocalDate currentDate = LocalDate.now();
// 将时间戳转换为LocalDate对象
        LocalDate timestampDate = Instant.ofEpochMilli(1691596800000L).atZone(ZoneId.systemDefault()).toLocalDate();
        System.out.println(timestampDate);
        LocalDate timestampDate1 = Instant.ofEpochMilli(1692287999000L).atZone(ZoneId.systemDefault()).toLocalDate();
        System.out.println(timestampDate1);
        String timestamp = String.valueOf(System.currentTimeMillis());
        Integer time = Integer.valueOf(timestamp.substring(0, timestamp.length() - 3));
        LocalDate timestampDate2 = Instant.ofEpochMilli(Long.parseLong(time.toString()+"000")).atZone(ZoneId.systemDefault()).toLocalDate();
        // 判断时间戳日期是否与当前日期相同
        System.out.println(timestampDate2);
        boolean isToday = currentDate.equals(timestampDate);

        if (isToday) {
            System.out.println("时间戳是今天");
        } else {
            System.out.println("时间戳不是今天");
        }
    }
}
